home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / E / Fireworks / FireWorksMod.e < prev    next >
Encoding:
Text File  |  1997-01-10  |  5.5 KB  |  215 lines

  1. /*
  2.  * FireWorks module
  3.  */
  4.  
  5. OPT MODULE
  6.  
  7. MODULE 'games','games/games','games/sound','*llist'
  8.  
  9. EXPORT DEF explosive:PTR TO sound
  10.  
  11. EXPORT SET FW_NODRAW,   -> Ignored
  12.            FW_KILLME,   -> Kill this spark asap
  13.            FW_MULTIHUE, -> Explosion will be multi-hued
  14.            FW_MASSIVE,  -> *BIG* explosion
  15.            FW_SMALL,    -> Little explosion, quick death
  16.            FW_HGRAV,    -> Heavy Gravity
  17.            FW_BIGSPARK, -> Sparks are 3x usual size
  18.            FW_IMAGE,    -> Explode into image, negates many other flags
  19.            FW_KEEPFLAGS,-> Children get the same flags, use with care.
  20.            FW_EXSOUND   -> Play the explosive sound.
  21.  
  22. EXPORT OBJECT firework OF node
  23.   x:LONG,y:LONG     -> X,Y position
  24.   xv:LONG,yv:LONG   -> X and Y velocities
  25.   gd:LONG     -> Gravity delay
  26.   gc:LONG     -> Gravity count
  27.   color:LONG  -> Color base
  28.   bg:LONG     -> Background color at current point
  29.   count:LONG  -> Count until death
  30.   ocount:LONG -> Death delay
  31.   excount:LONG -> If greater than 0, this firework will explode on death,
  32.                -> and the children will recieve self.excount-1
  33.   flags:LONG  -> Firework flags
  34.   iw,ih:LONG  -> Image HALF width/height
  35.   ip:PTR TO CHAR  -> Pointer to expimage
  36. ENDOBJECT
  37.  
  38. CONST S_BOTTOM=185
  39.  
  40. /****************************************************************************
  41. ** Draw the pixel into the display
  42. */
  43.  
  44. PROC draw(scn,buf) OF firework
  45.   DEF c,c2
  46.  
  47.   c:=self.color+3-((self.count*4)/self.ocount)
  48.   c2:=self.color+3
  49.  
  50.   DrawPixel(scn,buf,self.x,self.y,c)
  51.  
  52.   IF (self.flags AND FW_BIGSPARK)
  53.       DrawPixel(scn,buf,self.x+1,self.y,c2)
  54.       DrawPixel(scn,buf,self.x-1,self.y,c2)
  55.       DrawPixel(scn,buf,self.x,self.y+1,c2)
  56.       DrawPixel(scn,buf,self.x,self.y-1,c2)
  57.   ENDIF
  58. ENDPROC
  59.  
  60. /****************************************************************************
  61. ** Blank the firework.
  62. */
  63.  
  64. PROC clear(scn,buf) OF firework
  65.   DrawPixel(scn,buf,self.x,self.y,self.bg)
  66.  
  67.   IF (self.flags AND FW_BIGSPARK)
  68.       DrawPixel(scn,buf,self.x+1,self.y,self.bg)
  69.       DrawPixel(scn,buf,self.x-1,self.y,self.bg)
  70.       DrawPixel(scn,buf,self.x,self.y+1,self.bg)
  71.       DrawPixel(scn,buf,self.x,self.y-1,self.bg)
  72.   ENDIF
  73. ENDPROC
  74.  
  75. /****************************************************************************
  76. ** Initialise new firework
  77. */
  78.  
  79. PROC new(x,y,xv,yv,gd,color,bg,count,excount,flags,ix=NIL,iy=NIL,ip=NIL) OF firework
  80.   self.prev:=NIL
  81.   self.next:=NIL
  82.   self.x:=x
  83.   self.y:=y
  84.   self.xv:=xv
  85.   self.yv:=yv
  86.   self.gd:=gd
  87.   self.gc:=0
  88.   self.color:=color
  89.   self.bg:=bg
  90.   self.count:=count
  91.   self.ocount:=count
  92.   self.excount:=excount
  93.   self.flags:=flags
  94.   self.iw:=ix
  95.   self.ih:=iy
  96.   self.ip:=ip
  97. ENDPROC
  98.  
  99. /****************************************************************************
  100. ** Update firework
  101. */
  102.  
  103. PROC update(flist) OF firework
  104.  
  105. DEF fw:PTR TO firework,xn,yn,exsize,n,b=NIL,c,s,fl=NIL,g,yv
  106.  
  107.   self.x:=self.x+self.xv
  108.   self.y:=self.y-self.yv
  109.   IF FastRandom(5)=2 THEN self.x:=self.x+FastRandom(2)-1
  110.   b:=(self.y>1) AND (self.y<S_BOTTOM) AND (self.x>1) AND (self.x<319)
  111.  
  112.   IF ((self.count>0) AND b)
  113.     IF self.gc>self.gd
  114.       self.gc:=0
  115.       self.yv:=self.yv-1
  116.     ELSE
  117.       self.gc:=self.gc+1
  118.     ENDIF
  119.     self.count:=self.count-1
  120.   ELSE
  121.     IF b AND (self.excount>0)
  122.       exsize:=FastRandom(10)+25
  123.       IF (self.flags AND FW_MASSIVE)=NIL
  124.         IF self.excount=1 
  125.           n:=FastRandom(2)+1
  126.         ELSE
  127.           n:=1  -> So that multi-explos don't get too big
  128.         ENDIF
  129.       ELSE
  130.         self.excount:=1
  131.         n:=5
  132.       ENDIF
  133.  
  134.       IF (self.flags AND FW_SMALL)<>FALSE 
  135.         n:=1
  136.       ENDIF
  137.   
  138.       IF (self.flags AND FW_KEEPFLAGS)<>FALSE THEN fl:=self.flags
  139.       IF (self.flags AND FW_IMAGE)=FALSE
  140.  
  141.       IF (self.flags OR FW_BIGSPARK)
  142.          explosive.volume := FastRandom(90)+11
  143.          explosive.octave := FastRandom(20)*2+40
  144.          PlaySound(explosive)
  145.       ENDIF
  146.  
  147.         FOR yn:=-n TO n  
  148.           FOR xn:=-n TO n
  149.   
  150.             IF (self.flags AND FW_MULTIHUE) THEN c:=(FastRandom(6)*4)+8 ELSE c:=self.color
  151.  
  152.             IF (self.flags AND FW_SMALL)=FALSE 
  153.               s:=exsize+((FastRandom(3)-1)*10)
  154.             ELSE
  155.               s:=10
  156.             ENDIF
  157.  
  158.             IF (self.flags AND FW_HGRAV)
  159.               g:=1
  160.               yv:=yn+FastRandom(3)-2
  161.             ELSE
  162.               g:=FastRandom(3)*6+1
  163.               yv:=yn+self.yv+FastRandom(3)-1
  164.             ENDIF
  165.  
  166.             NEW fw.new(self.x,self.y,
  167.                        xn+self.xv+FastRandom(3)-1,
  168.                        yv,
  169.                        g,
  170.                        c,
  171.                        self.bg,
  172.                        s,
  173.                        self.excount-1,
  174.                        fl)
  175.             self.add(fw)
  176.  
  177.           ENDFOR
  178.         ENDFOR
  179.       ELSE
  180.         FOR yn:=-self.ih TO self.ih
  181.           FOR xn:=-self.iw TO self.iw
  182.             c:=(self.ip[((((self.iw*2)+2)*((-yn)+self.ih))+(xn+self.iw))])
  183.  
  184.             IF c>0
  185.               c:=self.color
  186.               s:=exsize+((FastRandom(3)-1)*10)
  187.               g:=2*6+1
  188.               yv:=yn
  189.  
  190.               explosive.volume := FastRandom(90)+11
  191.               explosive.octave := FastRandom(20)*2+40
  192.               PlaySound(explosive)
  193.  
  194.               NEW fw.new(self.x,self.y,
  195.                        xn+self.xv,
  196.                        yv,
  197.                        g,
  198.                        c,
  199.                        self.bg,
  200.                        s,
  201.                        self.excount-1,
  202.                        fl)
  203.  
  204.               self.add(fw)
  205.             ENDIF
  206.           ENDFOR
  207.         ENDFOR
  208.       ENDIF
  209.     ENDIF
  210.     IF flist=self THEN flist:=self.next
  211.     self.del()
  212.     self.flags:=FW_KILLME
  213.   ENDIF
  214. ENDPROC flist
  215.